{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Python 3 print 函数用法总结\n",
    "\n",
    "### 1.   输出字符串和数字\n",
    "\n",
    "\\>>>print(\"dalong10\")\\# 输出字符串\n",
    "\n",
    "dalong10\n",
    "\n",
    "\\>>> print(100)\\# 输出数字\n",
    "\n",
    "100\n",
    "\n",
    "\\>>> str ='dalong10'\n",
    "\n",
    "\\>>> print(str)\\# 输出变量\n",
    "\n",
    "dalong10\n",
    "\n",
    "\\>>> L =\\[1,2,'a'\\]\\# 列表\n",
    "\n",
    "\\>>> print(L)\n",
    "\n",
    "\\[1, 2, 'a'\\]\n",
    "\n",
    "\\>>> t =(1,2,'a')\\# 元组\n",
    "\n",
    "\\>>> print(t)\n",
    "\n",
    "(1, 2, 'a')\n",
    "\n",
    "\\>>> d ={'a':1, 'b':2} \\# 字典\n",
    "\n",
    "\\>>> print(d)\n",
    "\n",
    "{'a': 1, 'b': 2}\n",
    "\n",
    "### 2.   格式化输出整数\n",
    "\n",
    "\\>>>str =\"the length of (%s) is %d\" %('dalong10',len('dalong10'))\n",
    "\n",
    "\\>>> print(str)\n",
    "\n",
    "thelengthof(dalong10)is6\n",
    "\n",
    "支持参数格式化，与 C 语言的 printf 类似\n",
    "\n",
    "python字符串格式化符号:\n",
    "\n",
    "<table><tbody><tr><td><p><strong><span>&nbsp; </span><span>符</span><span>&nbsp;&nbsp; </span><span>号</span></strong></p></td><td><p><strong><span>描述</span></strong></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %c</span></p></td><td><p><span>&nbsp;</span><span>格式化字符及其ASCII</span>码</p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %s</span></p></td><td><p><span>&nbsp;</span><span>格式化字符串</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %d</span></p></td><td><p><span>&nbsp;</span><span>格式化整数</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %u</span></p></td><td><p><span>&nbsp;</span><span>格式化无符号整型</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %o</span></p></td><td><p><span>&nbsp;</span><span>格式化无符号八进制数</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %x</span></p></td><td><p><span>&nbsp;</span><span>格式化无符号十六进制数</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %X</span></p></td><td><p><span>&nbsp;</span><span>格式化无符号十六进制数（大写）</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %f</span></p></td><td><p><span>&nbsp;</span><span>格式化浮点数字，可指定小数点后的精度</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %e</span></p></td><td><p><span>&nbsp;</span><span>用科学计数法格式化浮点数</span></p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %E</span></p></td><td><p><span>&nbsp;</span><span>作用同%e</span>，用科学计数法格式化浮点数</p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %g</span></p></td><td><p><span>&nbsp;%f</span><span>和%e</span>的简写</p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %G</span></p></td><td><p><span>&nbsp;%f </span><span>和 %E </span>的简写</p></td></tr><tr><td><p><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %p</span></p></td><td><p><span>&nbsp;</span><span>用十六进制数格式化变量的地址</span></p></td></tr></tbody></table>\n",
    "\n",
    "格式化操作符辅助指令:\n",
    "\n",
    "<table><tbody><tr><td><p><strong><span>符号</span></strong></p></td><td><p><strong><span>功能</span></strong></p></td></tr><tr><td><p><span>*</span></p></td><td><p><span>定义宽度或者小数点精度</span></p></td></tr><tr><td><p><span>-</span></p></td><td><p><span>用做左对齐</span></p></td></tr><tr><td><p><span>+</span></p></td><td><p><span>在正数前面显示加号( + )</span></p></td></tr><tr><td><p><span>&lt;sp&gt;</span></p></td><td><p><span>在正数前面显示空格</span></p></td></tr><tr><td><p><span>#</span></p></td><td><p><span>在八进制数前面显示零('0')</span>，在十六进制前面显示'0x'或者'0X'(取决于用的是'x'还是'X')</p></td></tr><tr><td><p><span>0</span></p></td><td><p><span>显示的数字前面填充'0'</span>而不是默认的空格</p></td></tr><tr><td><p><span>%</span></p></td><td><p><span>'%%'</span><span>输出一个单一的'%'</span></p></td></tr><tr><td><p><span>(var)</span></p></td><td><p><span>映射变量(</span>字典参数)</p></td></tr><tr><td><p><span>m.n.</span></p></td><td><p><span>m </span><span>是显示的最小总宽度,n </span>是小数点后的位数(如果可用的话)</p></td></tr></tbody></table>\n",
    "\n",
    "### 3.   格式化输出16进制，十进制，八进制整数\n",
    "\n",
    "**%x--- hex 十六进制**\n",
    "\n",
    "**%d--- dec 十进制**\n",
    "\n",
    "**%o--- oct 八进制**\n",
    "\n",
    "\\>>>nHex =0xFF\n",
    "\n",
    "\\>>> print(\"nHex =%x,nDec = %d,nOct = %o\" %(nHex,nHex,nHex))\n",
    "\n",
    "nHex = ff,nDec = 255,nOct = 377\n",
    "\n",
    "### 4.   格式化输出浮点数(float)\n",
    "\n",
    "\\>>>pi =3.141592653\n",
    "\n",
    "\\>>> print('%10.3f' % pi)#字段宽10，精度3\n",
    "\n",
    "3.142\n",
    "\n",
    "\\>>> print(\"pi = %.\\*f\" % (3,pi))#用\\*从后面的元组中读取字段宽度或精度\n",
    "\n",
    "pi = 3.142\n",
    "\n",
    "\\>>> print('%010.3f' % pi)#用0填充空白\n",
    "\n",
    "000003.142\n",
    "\n",
    "\\>>> print('%-10.3f' % pi)#左对齐\n",
    "\n",
    "3.142\n",
    "\n",
    "\\>>> print('%+f' % pi)#显示正负号\n",
    "\n",
    "+3.141593\n",
    "\n",
    "### 5.   自动换行\n",
    "\n",
    "print 会自动在行末加上回车, 如果不需回车，只需在 print 语句的结尾添加一个逗号 , ，就可以改变它的行为。\n",
    "\n",
    "\\>>>for i in range(0,6):\n",
    "\n",
    "... print(i,)\n",
    "\n",
    "...\n",
    "\n",
    "0\n",
    "\n",
    "1\n",
    "\n",
    "2\n",
    "\n",
    "3\n",
    "\n",
    "4\n",
    "\n",
    "5\n",
    "\n",
    "### 6.   print 不换行\n",
    "\n",
    "在 Python 中 print 默认是换行的\n",
    "\n",
    "\\>>>for i in range(0,3):\n",
    "\n",
    "... print(i)\n",
    "\n",
    "...\n",
    "\n",
    "0\n",
    "\n",
    "1\n",
    "\n",
    "2\n",
    "\n",
    "\\>>> \n",
    "\n",
    "要想不换行你应该写成 **print(i, end = '' )**\n",
    "\n",
    "\\>>>for i in range(0,3):\n",
    "\n",
    "... print(i, end = '')\n",
    "\n",
    "...\n",
    "\n",
    "012\n",
    "\n",
    "\\>>>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}